package com.qd.system.treecl;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author sjk
 * @since 1.0.0
 */
@Data
@Accessors(chain = true)
public class TreeClDTO {

    /**
     * 原表表名
     */
    private String tableName;
    /**
     * 原表字段ID
     */
    private String tableColumnId = "id";
    /**
     * 原表父级字段ID
     */
    private String tableColumnPid = "parent_id";
    /**
     * 原表字段名称
     */
    private String tableColumnName = "name";
    /**
     * 参数，可以为空(查询、删除时候的条件)
     */
    private String param;
    /**
     * 参数，可以为空(查询、删除时候的条件),批量
     */
    private List<String> params;
    /**
     * cl表表名
     */
    private String clTableName;
    /**
     * cl表主键
     */
    private String clPrimaryKey = "cid";
    /**
     * cl表字段ID
     */
    private String clTableColumnId = "id";
    /**
     * cl父级字段ID
     */
    private String clTableColumnPid = "parent_id";
    /**
     * cl父级字段名称
     */
    private String clTableColumnParentName = "parent_name";
    /**
     * cl表字段名称
     */
    private String clTableColumnName = "name";
    /**
     * cl表字段层次
     */
    private String clTableColumnDistance = "distance";

    public TreeClDTO(String tableName) {
        this.tableName = tableName;
    }

    public TreeClDTO(String tableName, String tableColumnId, String tableColumnName) {
        this.tableName = tableName;
        this.tableColumnId = tableColumnId;
        this.tableColumnName = tableColumnName;
    }

    public String getClTableName() {
        if (!StringUtils.hasLength(clTableName)) {
            clTableName = tableName + "_cl";
        }
        return clTableName;
    }

    public void freeData() {
        this.tableName = null;
        this.tableColumnId = null;
        this.tableColumnPid = null;
        this.tableColumnName = null;
        this.param = null;
        this.clTableName = null;
        this.clPrimaryKey = null;
        this.clTableColumnId = null;
        this.clTableColumnPid = null;
        this.clTableColumnParentName = null;
        this.clTableColumnName = null;
        this.clTableColumnDistance = null;
    }
}